home *** CD-ROM | disk | FTP | other *** search
- unit SimpleDemoUnit;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, Parser10;
-
- type
- TSimpleDemoForm = class(TForm)
- Parser: TParser;
- ExpressionEdit: TEdit;
- ResultEdit: TEdit;
- CalcBtn: TButton;
- Label1: TLabel;
- Label2: TLabel;
- DefineFuncsBtn: TButton;
- DefineVarBtn: TButton;
- RemoveFuncsBtn: TButton;
- procedure CalcBtnClick(Sender: TObject);
- procedure DefineFuncsBtnClick(Sender: TObject);
- procedure RemoveFuncsBtnClick(Sender: TObject);
- procedure DefineVarBtnClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- SimpleDemoForm: TSimpleDemoForm;
-
- implementation
-
- {$R *.DFM}
-
- procedure TSimpleDemoForm.CalcBtnClick(Sender: TObject);
- begin
- // Setting the expression
- Parser.Expression := ExpressionEdit.Text;
- // Evaluating the expression
- ResultEdit.Text := FloatToStr(Parser.Value);
- end;
-
- procedure TestOneParam(AnOp: POperation);
- begin
- with AnOp^ do
- dest^ := arg1^*3;
- end;
-
- procedure TestTwoParam(AnOp: POperation);
- begin
- with AnOp^ do
- dest^ := arg1^ + arg2^*2;
- end;
-
- procedure TSimpleDemoForm.DefineFuncsBtnClick(Sender: TObject);
- begin
- // Adding functions
- Parser.AddFunctionOneParam('OneParam', TestOneParam);
- Parser.AddFunctionTwoParam('TwoParam', TestTwoParam);
- end;
-
- procedure TSimpleDemoForm.RemoveFuncsBtnClick(Sender: TObject);
- begin
- // Removing functions
- Parser.ClearFunction('OneParam');
- Parser.ClearFunction('TwoParam');
- end;
-
- procedure TSimpleDemoForm.DefineVarBtnClick(Sender: TObject);
- var
- MyVar2: PParserFloat;
- begin
- // Setting variables - slowly
- Parser.Variable['MyVar1'] := 3.14;
- MyVar2 := Parser.SetVariable('MyVar2', 0);
- // Setting variables - fast
- MyVar2^ := 50;
- // Setting built-in variables, fast
- Parser.A := 60;
- // Getting variables - slowly
- ShowMessage('Value of MyVar1 = ' + FloatToStr(Parser.Variable['MyVar1']));
- // Getting variables - fast
- ShowMessage('Value of MyVar2 = ' + FloatToStr(MyVar2^));
- // Getting built-in variables, fast
- ShowMessage('Value of A = ' + FloatToStr(Parser.A));
- end;
-
- end.
-